The present invention relates to computer graphics, and more particularly to shadow mapping in a graphics pipeline.
A major objective in graphics rendering is to produce images that are so realistic that the observer believes the image is real. A fundamental difficulty in achieving total visual realism is the complexity of accurately representing real world visual effects. A scene can include a wide variety of textures, subtle color gradations, reflections, translucency, etc. One important way to make images more realistic is to determine how objects in a scene cast shadows and then represent these shadows in the rendered image. Shadows enhance the realism of an image because they give a two-dimensional image a three-dimensional feel.
The addition of shadows to the rendering of a complex model can greatly enhance the understanding of that model""s geometry. The human visual system uses shadows as a cue for depth and shape. Consequently, shadows are very useful for conveying the three dimensional nature of rendered objects and for adding realism to computer generated scenes.
Generally, shadowing is similar to hidden surface removal. In hidden surface removal, objects or portions thereof are obscured because they are behind another object. For hidden surface removal, the point of reference for determining if an object is obscured is called a viewing point. For shadowing, objects or portions thereof are obscured because they are in the shadow of another object. In the shadowing case, the point of reference for determining if an object is obscured is a source light point. While many approaches exist for shadow mapping, depth map-based shadow algorithms are commonly used in graphics pipelines. Examples of such depth map-based shadow mapping algorithms are set forth in:
1) Lance Williams. Casting curved shadows on curved surfaces. In Proceedings of SIGGRAPH""78, pages 270-274, 1978;
2) Reeves, D. H. Salesin, R. L. Cook. Rendering antialiased shadows with depth maps. In Proceedings of SIGGRAPH""87, pages 283-291, 1987; and
3) M. Segal, C. Korobkin, R. van Widenfelt, J. Fordan, P. Haeberli. Fast Shadows and Lighting Effects Using Texture Mapping. In Proceedings of SIGGRAPH""92, pages 249-252, 1992.
which are each incorporated herein by reference in their entirety.
Prior Art FIG. 1 illustrates one depth map-based shadow algorithm 100 for generating realistic shadows. In such approach, there are two rendering passes 102 and 104. In the first pass 102, the scene is rendered from the point of view of a light source. The result is a depth map 106, or shadow map, which is essentially a two-dimensional function indicating the depth of the closest pixels to the light. In particular, each primitive, i.e. triangle, is scan-converted into pixels. A depth value, zlight, of the scanned fragment is interpolated across the primitive, and then is z-tested using a standard z-value (or any other depth value representation) buffer algorithm before being written out to the depth map 106. For additional information regarding such algorithm, reference may be made to the previously mentioned references in addition to: E. Catmull. A hidden surface Algorithm with Anti-Aliasing. In Siggraph""78, Page 6-11. 1978, which is incorporated herein by reference in its entirety.
Prior Art FIG. 2A illustrates the prior art technique 200 of building the shadow map using the standard z-buffer algorithm. As shown, distances 202 between a light source 204 and exposed surfaces of objects 206 are collected from a z-buffer. Depth values which are representative of the distances 202 are then utilized to generate the depth map 106.
For reasons that will soon become apparent, a polygon offset function may be performed in operation 108 for resolving a common self-shadowing aliasing problem. As an option, the polygon offset operation may include the xe2x80x9cglPolygonOffsetxe2x80x9d operation in accordance with the OpenGL(copyright) programming language.
In the second pass 104, the scene is rendered from the eye space. During the second pass 104, each primitive is scanned into the screen from the eye space. However, the position (x,y,z) in the eye space can be transformed via a standard projective texture mapping operation 110 into the light space to get a texture coordinates (s,t,r), where (s,t) are the texture coordinates of the sampled three-dimensional point projected on the depth map 106, while r is the depth value that corresponds to the distance of the sampled point to the light source. In the second pass it is important to note that the distance value, r, can possibly be scaled by a percentage value, hence is offset by a small percentage amount using the texgen matrix or a vertex program.
Thereafter, in operation 112, the depth value at the sampling point, r, is then compared with the offset depth value, zlight, stored in the depth map 106 generated in the first pass 102 to yield a light-occlusion result, i.e. r greater than zlight, if the sampled point is behind some objects which are closer to the light, hence it is in the shadow of those objects. The resultant binary shadow values are then used to shade the current scanned object, resulting in shadow effects. Prior Art FIG. 2B illustrates the various variables associated with the calculations carried out during the second pass 104. Finally, a shadow modulation operation 114 is performed, the details of which will be set forth hereinafter.
Since this two-pass approach requires resampling the depth map 106 in the second pass 104, the problem of self-shadow aliasing may occur. Prior Art FIG. 2C illustrates such aliasing problem that arises when shadow mapping in accordance with Prior Art FIGS. 1-2B. In particular, complications arise when various points on the objects 206 are rendered in light space via a single texel 210 during the first pass 102, and subsequently rendered by way of separate pixels 212 in eye space during the second pass 104.
Prior Art FIG. 3A illustrates the offset operation 108 of Prior Art FIG. 1 which represents a solution to the aliasing problem of Prior Art FIG. 2C. As shown, the depth value, zlight, may be bounded by the xe2x80x9cglPolygonOffsetxe2x80x9d operation. In particular, the xe2x80x9cglPolygonOffsetxe2x80x9d operation includes calculating an offset value, o, using Prior Art Equations A.
zlight=z+o, where: 
xe2x80x83o=m*factor+r*units, where:
m=max(abs(xcex4z/xcex4x), abs(xcex4z/xcex4y)), where 
r is defined in Prior Art FIG. 2B,
factor=a scalar that scales the maximum depth slope m of the polygon; and
units=a scalar that scales an implementation-dependent constant that relates to the usable resolution of the depth buffer. Both factor and units may be positive or negative.
See equations 3.6 and 3.7 of the OpenGL 1.2.1 specification that can be found at http://www.opengl.org/Documentation/Specs.html, and which is incorporated herein by reference.
By offsetting the depth value, zlight, the self-shadow aliasing of Prior Art FIG. 2C is avoided. In particular, the offset operation dynamically compensates for the depth variation within each texel of the depth map 106.
Prior Art FIG. 3B illustrates a limitation associated with the prior art solution of Prior Art FIG. 3A. In some instances the values xcex4z/xcex4x and xcex4z/xcex4y of Equations A are unbounded due to the severe depth slopes of the nearly edge-on objects 206. This can lead to erroneous results, i.e. false shadows, when using the offset equation set forth hereinabove.
Various additional prior art techniques have been developed for addressing the problem of self-shadow aliasing. For example, shadows can be softened at the shadow boundaries, as set forth in the following document: W. Reeves, D. H. Salesin, R. L. Cook. Rendering antialiased shadows with depth maps. In Proceedings of SIGGRAPH""87, pages 283-291, 1987, which is incorporated herein by reference in its entirety. Variations of this technique are widely used and implemented for real or non-real time systems. Yet another solution includes the xe2x80x9cSGIX_shadowxe2x80x9d operation in accordance with the OpenGL(copyright) programming language.
Other techniques that can be used to suppress aliasing artifacts include:
1) Increasing the shadow map spatial resolution. This increases the number of depth samples to compare against, which results in a more accurate shadow.
2) Jittering the shadow map samples by modifying the projection in the texture transformation matrix. The results of the depth comparisons can then be averaged to smooth out shadow edges.
3) Modifying the texture projection matrix so that the r values are biased by a small amount. Further, the r values may be scaled, thus moving the objects a little closer to the light. This prevents sampling errors from causing a curved surface to shadow itself. This r scaling can also be done with the offset operation.
Additional solutions to the self-shadowing aliasing problem are set forth in:
1) A. Woo. The Shadow Depth map revisited. In Graphics Gem III, pages 338-342, 1992;
2) M. Woo, J. Neider, T. Davis. In OpenGL programming Guide, second edition, version 1.1.1997;
3) M Kilgard. Shadow Mapping with Today""s OpenGL Hardware. GDC 2000:Advanced OpenGL Game Development, 2000;
4) Wolfgang Heidrich, PhD thesis, 1999;
5) Alan Watt and Mark Watt, Advanced Animation and Rendering Techniques. By ACM Press, New York, N.Y. 1992, which are each incorporated herein by reference in their entirety.
While the foregoing techniques address the self-shadow aliasing problem by reducing the associated affects, they still merely provide a balance between efficiency and limitation issues. There is thus a need for an improved shadowing algorithm in a graphics pipeline that exploits the strengths of the prior art techniques such as the offset operation, while avoiding the problems and limitations associated therewith.
In operation 114, a shadow modulation process with the current standard openGL graphics pipeline is carried out in a single function:
Color=(1xe2x88x92s)*(colorxe2x80x94amb+colorxe2x80x94diff+colorxe2x80x94spec), 
where s is a shadow variable, Color_diff is a diffuse color variable, Color_spec is a specular color variable, and Color_amb is an ambient color variable. This technique is very limited in its flexibility since it shadows a superposition of diffuse color and ambient color by simply adding them before entering the pixel shading logic. There is thus a further need for a shadowing algorithm in a graphics pipeline that includes a flexible way of implementing shadow modulation.
A system, method and article of manufacture are provided for shadow mapping while rendering a primitive in a graphics pipeline. Initially, an offset operation is performed in order to generate a depth value while rendering a primitive. Further, a value of a slope associated with a triangle is identified. Thereafter, the depth value is conditionally clamped to the depth gamut of the triangle based on the value of the slope of the triangle.
In one embodiment of the present invention, the shadow mapping process includes rendering the primitive from a light space perspective. The offset operation may include a polygon offset operation in accordance with the OpenGL(copyright) programming language. Further, the depth value may be clamped if the value of the slope is greater than a predetermined amount.
In another embodiment of the present invention, the clamping may include identifying vertex depth values of vertices of the primitive, and comparing at least one of the vertex depth values with the depth value generated by the offset operation. Thereafter, the depth value generated by the offset operation may be clamped based on the comparison.
In one aspect, the depth value generated by the offset operation may be clamped to the offset operation depth value if such offset operation depth value is less than the greatest vertex depth value. Further, the depth value generated by the offset operation may be clamped to the greatest vertex depth value if the greatest vertex depth value is less than the depth value generated by the offset operation.
In another aspect, the depth value generated by the offset operation may be clamped to the offset operation depth value if such depth value is greater than the least vertex depth value. Further, the depth value generated by the offset operation may be clamped to the least vertex depth value if the least vertex depth value is greater than the depth value generated by the offset operation.
In accordance with another embodiment of the present invention, a technique may be provided for performing shading calculations in a graphics pipeline. Initially, a first shading calculation may be performed in order to generate output, after which such output may be saved. A second shading calculation may also be performed using the saved output in order to generate further output.
In one embodiment, the first shading calculation may include:
[(1xe2x88x92s)*(Color_diff+Color_spec)]
for generating an output A, and the second shading calculation may include:
[Colorxe2x80x94amb+A], 
where s is a shadow variable, Color_diff is a diffuse color variable, Color spec is a specular color variable, and Color_amb is an ambient color variable. It should be noted that s, the shadow variable, generally takes values in the range 0.0 to 1.0, where 0.0 could represent being completely unshadowed and 1.0 being completely shadowed. The shadow variable s is computed by normal texture filtering of the results obtained in the second pass of the shadow algorithm.
In yet another embodiment, the first shading calculation may include:
[((1xe2x88x92s)*Color_diff)+Color_amb]
for generating an output A, and the second shading calculation may include:
[A*Texture_det+(1xe2x88x92s)*Color_spec], 
where s is a shadow variable, Color_diff is a diffuse color variable, Color spec is a specular color variable, Color_amb is an ambient color variable, and Texture_det is a detail texture variable.
As such, the first and second shading calculations may together include a diffuse color variable, a specular color variable, and an ambient color variable, while ensuring that such variables remain decoupled. These and other advantages of the present invention will become apparent upon reading the following detailed description and studying the various figures of the drawings.